package com.xiaohudie.JUC;

/**
 * @Author xiao hu die
 * @Date 2022/1/16 0:31
 * @Version 1.0
 */

import java.util.concurrent.*;

/**自定义线程池*/
public class Thread15 {
    public static void main(String[] args) {
        ExecutorService executorService = new ThreadPoolExecutor(
                /**主线程数量*/
                2,
                /**最大线程数量*/
                5,
                /**线程等待时间*/
                2L,
                /**等待时间的单位时分秒*/
                TimeUnit.SECONDS,
                /**新建阻塞队列*/
                new ArrayBlockingQueue<>(3),
                /**线程工厂*/
                Executors.defaultThreadFactory(),
                /**拒绝策略,JDK默认4个*/
                new ThreadPoolExecutor.CallerRunsPolicy()
        );
        /**模拟自己使用线程池实现*/
        try {
            for (int i = 0; i < 20; i++) {
                executorService.execute(()->{
                    System.out.println(Thread.currentThread().getName()+"正在处理业务员");
                });
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            executorService.shutdown();
        }

    }
}
